package com.xuecheng.media.domain.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xuecheng.media.domain.mapper.UploadRecordMapper;
import com.xuecheng.media.domain.model.entity.UploadRecord;
import com.xuecheng.media.domain.service.UploadRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @Author: LiJunXi
 * @Description:
 * @Date: 2024-08-18  10:47
 */
@Service
public class UploadRecordServiceImpl extends ServiceImpl<UploadRecordMapper, UploadRecord> implements UploadRecordService {

    @Autowired
    private UploadRecordMapper uploadRecordMapper;

    @Override
    public List<UploadRecord> getWaitClearRecordList(Integer shardIndex, Integer shardTotal, Integer processors) {
        LocalDateTime now = LocalDateTime.now();
        List<UploadRecord> waitClearRecordList = uploadRecordMapper.getWaitClearRecordList(shardIndex, shardTotal, processors);
        // 选出处理时间超过两小时的上传任务
        return waitClearRecordList.stream()
                .filter(item -> item.getCreateTime().isBefore(now.minusHours(2)))
                .collect(Collectors.toList());
    }

}
